# Contributor: Díaz Urbaneja Diego <sodomon2@gmail.com>
# Maintainer: Díaz Urbaneja Diego <sodomon2@gmail.com>
pkgname=ppsspp
pkgver=1.9
pkgrel=2
pkgdesc="PPSSPP - a fast and portable PSP emulator"
url="https://www.ppsspp.org/"
arch="x86_64"  # only available on x86_64 due to compiling problems
_armips_commit="7885552b208493a6a0f21663770c446c3ba65576"
_discord_commit="3d3ae7129d17643bc706da0a2eea85aafd10ab3a"
_glslang_commit="f9d08a25fbe17e0677a89d398f4d7f232339c3f9"
_spirv_cross_commit="a1f7c8dc8ea2f94443951ee27003bffa562c1f13"
_rapidjson_commit="73063f5002612c6bf64fe24f851cd5cc0d83eef9"
_lang_commit="bfc3a511f60e84de4d49170e2c442ac36b09cdfd"
_ffmpeg_commit="90701640c7f458461310b54e7d4041230e2d5d5a"
license="GPL-2.0-only"
makedepends="make glew-dev libzip-dev snappy-dev mesa-dev qt5-qtbase-dev zlib-dev sdl2-dev cmake coreutils"
options="!check" # make check not implemented
source="ppsspp-$pkgver.tar.gz::https://github.com/hrydgard/ppsspp/archive/v$pkgver.tar.gz
	ppsspp-$pkgver-armips.tar.gz::https://github.com/Kingcom/armips/archive/$_armips_commit.tar.gz
	ppsspp-$pkgver-discord-rpc.tar.gz::https://github.com/discordapp/discord-rpc/archive/$_discord_commit.tar.gz
	ppsspp-$pkgver-glslang.tar.gz::https://github.com/hrydgard/glslang/archive/$_glslang_commit.tar.gz
	ppsspp-$pkgver-SPIRV-Cross.tar.gz::https://github.com/KhronosGroup/SPIRV-Cross/archive/$_spirv_cross_commit.tar.gz
	ppsspp-$pkgver-rapidjson.tar.gz::https://github.com/Tencent/rapidjson/archive/$_rapidjson_commit.tar.gz
	ppsspp-$pkgver-lang.tar.gz::https://github.com/hrydgard/ppsspp-lang/archive/$_lang_commit.tar.gz
	ppsspp-$pkgver-ffmpeg.tar.gz::https://github.com/hrydgard/ppsspp-ffmpeg/archive/$_ffmpeg_commit.tar.gz
	ppsspp.desktop
	ppsspp
	ppsspp-version.patch
	ppsspp-headless"

prepare() {
	default_prepare
	# adding submodules needed by ppsspp
	mv "$srcdir/"armips-$_armips_commit/* "$builddir"/ext/armips/
	mv "$srcdir/"discord-rpc-$_discord_commit/* "$builddir"/ext/discord-rpc/
	mv "$srcdir/"glslang-$_glslang_commit/* "$builddir"/ext/glslang/
	mv "$srcdir/"rapidjson-$_rapidjson_commit/* "$builddir"/ext/rapidjson/
	mv "$srcdir/"SPIRV-Cross-$_spirv_cross_commit/* "$builddir"/ext/SPIRV-Cross/
	mv "$srcdir/"$pkgname-lang-$_lang_commit/* "$builddir"/assets/lang/
	mv "$srcdir/"$pkgname-ffmpeg-$_ffmpeg_commit/* "$builddir"/ffmpeg
	cd "$builddir"/ffmpeg
	./linux_x86-64.sh
}

build() {
	mkdir build-qt
	cd build-qt
	cmake .. \
		-DUSING_QT_UI=ON \
		-DHEADLESS=ON
		make
}

package() {
	mkdir -p "$pkgdir"/usr/bin
	install -m 755 $srcdir/ppsspp "$pkgdir"/usr/bin/ppsspp
	install -m 755 $srcdir/ppsspp-headless "$pkgdir"/usr/bin/ppsspp-headless
	mkdir -p "$pkgdir"/usr/share/ppsspp
	mv build-qt/assets "$pkgdir"/usr/share/ppsspp
	cp -Rp build-qt/PPSSPPQt "$pkgdir"/usr/share/ppsspp
	cp -Rp build-qt/PPSSPPHeadless "$pkgdir"/usr/share/ppsspp
	mkdir -p "$pkgdir"/usr/share/applications
	install -m 644 $srcdir/ppsspp.desktop "$pkgdir"/usr/share/applications/ppsspp.desktop
	mkdir -p "$pkgdir"/usr/share/pixmaps
	install -m 644 icons/icon-512.svg "$pkgdir"/usr/share/pixmaps/ppsspp.svg
}

sha512sums="10114014cb9df93326b6dcbe754b0fa7c80afcf201dbc50a40613e73ad1daf713b285629fbd63ed9c250d6f5ac4cb47331ca5167d65f49ad69d3c1af42daf258  ppsspp-1.9.tar.gz
2a94e2c7b7280c00a39c8fc92d81ed15fc4b3270a124ef882e3cd8878db6ec827aefa06b0e646a60916636a95e4ebfa886e9878ba70c6bcfcd048def457368be  ppsspp-1.9-armips.tar.gz
17fb5de5d5afea9b7e0cdc116d5e3611b147eb2cde3a295a1a4ceb688bceb93d54feb2e479d511ce39d53a1380462a75dcdf6be9ddc2cece9d44b7f8ff7504af  ppsspp-1.9-discord-rpc.tar.gz
6360a09a7fd69652f84c4b85e1705baf9fecfe53c862625e22e5da1574fa4c2d4d14054bdfd49c5096ce93b371db286cefa28981550b6732ddaac64a7ed09c34  ppsspp-1.9-glslang.tar.gz
b3faff10e2578a27740a013e463750c5244796e651b9586f900a3c97adba060f5e978d47a411f9fb255dd8314e21ea54cccbf90f726d1779448d5dc030f64b65  ppsspp-1.9-SPIRV-Cross.tar.gz
3472e129e710bf5343b8b27a61581a1480c8096493e466440b62702d8b5353745d561931f72b5405a736ad92525be3843ea1cf4b5ea5839721cc6d6b358f19bc  ppsspp-1.9-rapidjson.tar.gz
8f0fa9b117e6637911985a6b6a642f94c3d98ad75b1f557dc6511989c695f1e6641ad5ca0f08c6852e514ebe514d3eaae27526cd744179421a39ab0cc48b40c0  ppsspp-1.9-lang.tar.gz
e7ce75109dc74cf353e89805059c9b08b07b6f0c14504ea437712904f8980c9526b8b2844573b610d7775b9eafc6f7184b6c4496ba088fc689e580b5c62d5016  ppsspp-1.9-ffmpeg.tar.gz
fb8c6c4a48003dac866b094f4d9d750bf7d1def14c9d3bf7a70f584ba187dacd5e57b29313e302740f5a0ec4bf27b6fea3d5cf27ae12bf6fac06f5a8ab23195b  ppsspp.desktop
c22214c15b6e9305f688c25c5997248a6a04c2dc229ea8c2126f0d288be7386134d15fc210e07f70f7eee13b0ab7ff05befd5657de0fc897d947f23c94711cd0  ppsspp
3a4360b433149e5a9e6eed7d6330f2ecf4911bac76f23570596d413147e2aed44cf168290fac5c807d260fa6540672ac5d53ce95120bd5d348e95243fa53ffd3  ppsspp-version.patch
6bf0dbe793cadbaa59199d0c0c169609db619ac4bb4bf33f226e5503765a9fb090c919a757b990396d3a744dfa217bc34c3a47e5e601a94da47b351035639113  ppsspp-headless"
